<?php
/**
 * 公用厨房消息模版
 */
class KitchenMsgtpl extends BaseMsgtpl
{
	/**
	 * 开始充电给用户发消息
	 * @param array $WechatUserInfo 微信用户信息
	 * @param array $kitchenId 充电模块id
	 * @param array $value 充电时长
	 * @param array $chargingLogId 充电记录id
	 */
	public function sendMessageToUser($WechatUserInfo,$kitchenId,$value,$kitchenLogId)
	{
		$url = C('site_url')."/base/kitchen/charging/kitchenId/".$kitchenId.'/id/'.$kitchenLogId;
		

		if($WechatUserInfo['wechat_id'] == 1){   // 青橄榄研发中心 测试
			$this->wxTplSign = 'BypiRvSt1PW5vTRbvukx0kYtPrh7_naMEFwqhhmgU4w';
		}elseif($WechatUserInfo['wechat_id'] == 3){  // 充电保
			$this->wxTplSign = '11a1hDxR5bN8xX_H8xUegvDer2snqx-uphAWW7S1Pyo';
		}elseif($WechatUserInfo['wechat_id'] == 2){   // 滨江后勤
			$this->wxTplSign = 'DkBMAbWr7JFFyY06kEM1trA_QzCwkGYbpU9vCLYUeQU';
		}elseif($WechatUserInfo['wechat_id'] == 5){  // 农林
			$this->wxTplSign = 'Nt9qtrcHnykGmaqSVXnh5Etw4MjTHw-DhmCpz47vcS0';
		}elseif($WechatUserInfo['wechat_id'] == 7){   // 杭师大
			$this->wxTplSign = 'gxAzaUq_99uqkX9ZNrFfC7q7iaQgDUS9_mYnuT9Scc0';
		}

		if($WechatUserInfo['wechat_id'] == 1){
			$info = array(
				'first' => array("value" => '尊敬的用户，您已开始使用公用厨房'),
				'keyword1' => array("value" => date("Y-m-d H:i:s")),
				'keyword2' => array("value" => $value.'分钟'),
				'remark' => array("value" => "在享受烹饪乐趣的同时,请爱护厨房设备,谢谢配合"),
			);
		}else{
			$info = array(
				'first' => array("value" => '尊敬的用户，您已开始使用公用厨房'),
				'keyword1' => array("value" => date("Y-m-d H:i:s")),
				'keyword2' => array("value" => $value.'分钟'),
				'keyword3' => array("value" => date('Y-m-d H:i:s',time()+$value*60)),
				'remark' => array("value" => "在享受烹饪乐趣的同时,请爱护厨房设备,谢谢配合"),
			);
		}


		$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $WechatUserInfo['openid'], $this->wxTplSign, $info, $url);
	}


	/**
	 * 结束充电给用户发消息
	 * @param array $WechatUserInfo 微信用户信息
	 * @param array $kitchenId 充电模块id
	 * @param array $logInfo 记录信息
	 */
	public function sendMessageToUser2($WechatUserInfo,$logInfo,$kitchenId)
	{
		
		$url = C('site_url')."/base/kitchen/index/kitchenId/".$kitchenId;
		if($WechatUserInfo['wechat_id'] == 1){   // 青橄榄研发中心 测试
			$this->wxTplSign = 'BypiRvSt1PW5vTRbvukx0kYtPrh7_naMEFwqhhmgU4w';
		}elseif($WechatUserInfo['wechat_id'] == 3){  // 充电保
			$this->wxTplSign = '11a1hDxR5bN8xX_H8xUegvDer2snqx-uphAWW7S1Pyo';
		}elseif($WechatUserInfo['wechat_id'] == 2){   // 滨江后勤
			$this->wxTplSign = 'DkBMAbWr7JFFyY06kEM1trA_QzCwkGYbpU9vCLYUeQU';
		}elseif($WechatUserInfo['wechat_id'] == 5){  // 农林
			$this->wxTplSign = 'Nt9qtrcHnykGmaqSVXnh5Etw4MjTHw-DhmCpz47vcS0';
		}elseif($WechatUserInfo['wechat_id'] == 7){   // 杭师大
			$this->wxTplSign = 'gxAzaUq_99uqkX9ZNrFfC7q7iaQgDUS9_mYnuT9Scc0';
		}

		if($WechatUserInfo['wechat_id'] == 1){
			$info = array(
				'first' => array("value" => '尊敬的用户,您已结束公用厨房的使用'),
				'keyword1' => array("value" => date("Y-m-d H:i:s",$logInfo['start_time'])),
				'keyword2' => array("value" => $logInfo['freezing_time'].'分钟'),
				'keyword3' => array("value" => date('Y-m-d H:i:s')),
				'remark' => array("value" => "请将多余的料理整理带走或丢入垃圾桶,营造一个清洁卫生的烹饪环境,谢谢您的配合",'color'=>'#FF0000'),
			);
		}else{
			$info = array(
				'first' => array("value" => '尊敬的用户,您已结束公用厨房的使用'),
				'keyword1' => array("value" => date("Y-m-d H:i:s",$logInfo['start_time'])),
				'keyword2' => array("value" => $logInfo['freezing_time'].'分钟'),
				'keyword3' => array("value" => date('Y-m-d H:i:s')),
				'remark' => array("value" => "请将多余的料理整理带走或丢入垃圾桶,营造一个清洁卫生的烹饪环境,谢谢您的配合",'color'=>'#FF0000'),
			);
		}


		$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $WechatUserInfo['openid'], $this->wxTplSign, $info, $url);
	}


	/**
	 * 异常结束充电给用户发消息
	 * @param array $WechatUserInfo 微信用户信息
	 * @param array $kitchenId 充电模块id
	 * @param array $logInfo 记录信息
	 */
	public function sendMessageToUser3($WechatUserInfo,$logInfo,$kitchenId,$eventCode)
	{
		$url = C('site_url')."/base/kitchen/index/kitchenId/".$kitchenId;
		if($WechatUserInfo['wechat_id'] == 1){   // 青橄榄研发中心 测试
			$this->wxTplSign = 'BypiRvSt1PW5vTRbvukx0kYtPrh7_naMEFwqhhmgU4w';
		}elseif($WechatUserInfo['wechat_id'] == 3){  // 充电保
			$this->wxTplSign = '11a1hDxR5bN8xX_H8xUegvDer2snqx-uphAWW7S1Pyo';
		}elseif($WechatUserInfo['wechat_id'] == 2){   // 滨江后勤
			$this->wxTplSign = 'DkBMAbWr7JFFyY06kEM1trA_QzCwkGYbpU9vCLYUeQU';
		}elseif($WechatUserInfo['wechat_id'] == 5){  // 农林
			$this->wxTplSign = 'Nt9qtrcHnykGmaqSVXnh5Etw4MjTHw-DhmCpz47vcS0';
		}elseif($WechatUserInfo['wechat_id'] == 7){   // 杭师大
			$this->wxTplSign = 'gxAzaUq_99uqkX9ZNrFfC7q7iaQgDUS9_mYnuT9Scc0';
		}

		$arr = array('34'=>'电流过载','35'=>'异常插拔','37'=>'未插入扫码');

		if($WechatUserInfo['wechat_id'] == 1){
			$info = array(
				'first' => array("value" => '尊敬的用户,您已结束公用厨房的使用'),
				'keyword1' => array("value" => date("Y-m-d H:i:s",$logInfo['start_time'])),
				'keyword2' => array("value" => $logInfo['freezing_time'].'分钟'),
				'keyword3' => array("value" => date('Y-m-d H:i:s')),
				'remark' => array("value" => "请将多余的料理整理带走或丢入垃圾桶,营造一个清洁卫生的烹饪环境,谢谢您的配合！",'color'=>'#FF0000'),
			);
		}else{
			$info = array(
				'first' => array("value" => '尊敬的用户,您已结束公用厨房的使用'),
				'keyword1' => array("value" => date("Y-m-d H:i:s",$logInfo['start_time'])),
				'keyword2' => array("value" => $logInfo['freezing_time'].'分钟'),
				'keyword3' => array("value" => date('Y-m-d H:i:s')),
				'remark' => array("value" => "厨房使用已异常终止(".$arr[$eventCode].")，已停止扣费。如设备有异常请联系专业人员修理",'color'=>'#FF0000'),
			);
		}


		$rs =$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $WechatUserInfo['openid'], $this->wxTplSign, $info, $url);
	}



	/**
	 * 异常提醒，给开发者（模块报警已修改使用sendMessageToUser5()）
	 * @param int $time  异常时间
	 * @param array $type 异常类型 1:模块，2：终端
	 * @param array $arr 异常信息
	 */
	public function sendMessageToUser4($time,$type,$str)
	{
		$url = '';
		$msg = ($type==1?'模块':'终端');
		$first = ($type==1?'启奏皇上，有模块大臣在罢工！':'哎呀，不得了啦，终端又在玩绝食！');
		$this->wxTplSign = 'ncyLzi_8xrTW8RdSKw9tN2AA4uXa-Ub7uGIbMAXjBDE';

		$info = array(
				'first' => array("value" => $first),
				'keyword1' => array("value" => date("Y-m-d H:i:s",$time)),
				'keyword2' => array("value" => $msg.'报警'),
				'remark' => array("value" => $str.'已长时间未响应,请速速安抚！')
			);

		//发送的openid列表
		$openidArr = array(
			'oJNYCsxwxNcwfHSVFsJVcpf4zoPc',//晓林
			'oJNYCsw6VIyHp_KZiyRmLljt6myg',//刘老师
			'oJNYCs4LqVeCtvsI-2XBuzBazSkc', //何升旭
			'oJNYCs_hle6tTbChzzj50hJqZwFk',//徐军彪
			'oJNYCszLPtrZQPi2qh3y6DrKTIPo',//王梓宇
			'oJNYCs_DCTO2E3WpJt9mHv-BVwxo', //黄工
			'oJNYCs7Rnb7FCvR2Fg6k4yrCvDOg',	//何升韩
			'oJNYCsyvRLOEvtheQEGHysGkh5h4'  //吴君鹏
			);
		foreach($openidArr as $v){
			$rs =$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $v, $this->wxTplSign, $info, $url);
		}
		
	}


	/**
	 * 模块异常提醒，给开发者(重点报警)
	 * @param int $time  异常时间
	 * @param array $type 异常类型 1:模块，2：终端
	 * @param array $arr 异常信息
	 */
	public function sendMessageToUser5($time,$type,$str)
	{
		$url = '';
		$first = '启奏皇上，有模块大臣在罢工！';
		$color = $type == 2?'#FF0000':'#000000';
		$this->wxTplSign = 'ncyLzi_8xrTW8RdSKw9tN2AA4uXa-Ub7uGIbMAXjBDE';

		$info = array(
				'first' => array("value" => $first,'color'=>$color),
				'keyword1' => array("value" => date("Y-m-d H:i:s",$time)),
				'keyword2' => array("value" => '模块报警'),
				'remark' => array("value" => $str,'color'=>$color)
			);

		//发送的openid列表
		$openidArr = array(
			'oJNYCsxwxNcwfHSVFsJVcpf4zoPc',//晓林
			'oJNYCsw6VIyHp_KZiyRmLljt6myg',//刘老师
			'oJNYCs4LqVeCtvsI-2XBuzBazSkc', //何升旭
			'oJNYCs_hle6tTbChzzj50hJqZwFk',//徐军彪
			'oJNYCszLPtrZQPi2qh3y6DrKTIPo',//王梓宇
			'oJNYCs_DCTO2E3WpJt9mHv-BVwxo', //黄工
			'oJNYCs7Rnb7FCvR2Fg6k4yrCvDOg',	//何升韩
			'oJNYCsyvRLOEvtheQEGHysGkh5h4'  //吴君鹏
			);
		foreach($openidArr as $v){
			$rs =$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $v, $this->wxTplSign, $info, $url);
		}
		
	}
}
